﻿using System;
using System.Collections.Generic;
using System.Drawing;

using NGE;

namespace MH.MENU
{
    public class BagOps : Panelbox
    {
        public BagOps(Game g)
            : base(g)
        {
            this.OnPanelboxOpen += new MenuEvent(BagOps_OnPanelboxOpen);
            this.OnPanelboxClose += new MenuEvent(BagOps_OnPanelboxClose);

            Name = "背包-操作";
            BGColor = Color.Gray;

            Location = new Microsoft.DirectX.Vector3(40, 120, 0);
            Size = new System.Drawing.Size(240, 80);

            msg = new Textbox();

            use = new Buttonbox();
            use.Textbox.Text = "使用/装备";
            use.Location = new Microsoft.DirectX.Vector3(0, 20, 0);
            use.OnButtonboxEvent += new MenuEvent(use_OnButtonboxEvent);

            give = new Buttonbox();
            give.Textbox.Text = "转交";
            give.Location = new Microsoft.DirectX.Vector3(0, 40, 0);
            give.OnButtonboxEvent += new MenuEvent(give_OnButtonboxEvent);

            drop = new Buttonbox();
            drop.Textbox.Text = "丢弃";
            drop.Location = new Microsoft.DirectX.Vector3(0, 60, 0);

            drop.OnButtonboxEvent += new MenuEvent(drop_OnButtonboxEvent);


            AddElement(msg);
            AddElement(use);
            AddElement(give);
            AddElement(drop);
        }

        void BagOps_OnPanelboxClose(object sender, object arg)
        {
            scriptCOM.SetValue("menu_return", "0");
        }

        void BagOps_OnPanelboxOpen(object sender, object arg)
        {
            scriptCOM.AS("var menu_return");
            if (arg != null)
            {
                string str = (string)arg;
                msg.Text = str;
            }
        }

        void drop_OnButtonboxEvent(object sender, object arg)
        {
            ButtonboxState bs = (ButtonboxState)arg;
            if (bs == ButtonboxState.Up)
            {
                scriptCOM.AS("menu close", false);
                scriptCOM.AS("var menu_return 3", false);
            }
        }

        void give_OnButtonboxEvent(object sender, object arg)
        {
            ButtonboxState bs = (ButtonboxState)arg;
            if (bs == ButtonboxState.Up)
            {
                scriptCOM.AS("menu close", false);
                scriptCOM.AS("var menu_return 2", false);
            }
        }

        void use_OnButtonboxEvent(object sender, object arg)
        {
            ButtonboxState bs = (ButtonboxState)arg;
            if (bs == ButtonboxState.Up)
            {
                scriptCOM.AS("menu close", false);
                scriptCOM.AS("var menu_return 1", false);
            }
        }
        SceneComponent sceneCOM
        {
            get
            {
                return ((SceneComponent)game.GetComponent("SceneCOM"));
            }
        }
        ScriptComponent scriptCOM
        {
            get
            {
                return ((ScriptComponent)game.GetComponent("ScriptCOM"));
            }
        }

        Textbox msg;
        Buttonbox use;
        Buttonbox give;
        Buttonbox drop;
    }
}
